1 Imports System.IO
2 Imports System.Security.Cryptography
3 Imports System.Text
4 Public Class frmPayment
5
6 #Region
"Controlbox"
7
8     Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
9         Me.Close()
10         LstOrder.Items.Clear()
11         txtAmount.Clear()
12         txtCash.Text =
"0.00"
13         txtChange.Text =
"0.00"
14     End Sub
15
16 #End Region
17
18     Public Shared Function GetUniqueKey(ByVal maxSize As Integer) As String
19         Dim chars As Char() = New Char(
61) {}
20         chars =
"123456789".ToCharArray()
21         Dim data As Byte() = New Byte(
0) {}
22         Dim crypto As New RNGCryptoServiceProvider()
23         crypto.GetNonZeroBytes(data)
24         data = New Byte(maxSize -
1) {}
25         crypto.GetNonZeroBytes(data)
26         Dim result As New StringBuilder(maxSize)
27         For Each b As Byte In data
28             result.Append(chars(b Mod (chars.Length)))
29         Next
30         Return result.ToString()
31     End Function
32
33     Private Sub txtCash_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCash.TextChanged
34         txtChange.Text = Format(Val(txtCash.Text) - Val(txtAmount.Text),
"###,##0.00")
35     End Sub
36
37     Private Sub BtnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDone.Click
38         If Val(txtAmount.Text) > Val(txtCash.Text) Then
39             MessageBox.Show(
"Please Enter cash value higher than the total amount.", "Invalid Cash", MessageBoxButtons.OK, MessageBoxIcon.Error)
40         Else
41             Dim prodname As String =
""
42             
'If frmMenu.prod.StartsWith(",") = True Then
43             
' prodname = frmMenu.prod.Remove(0, 1)
44             
'End If
45             For i =
0 To Me.LstOrder.Items.Count - 1
46                 prodname = prodname &
"," & LstOrder.Items(i).ToString.Replace("& vbcrlf", "")
47             Next i
48             If prodname.StartsWith(
",") = True Then
49                 prodname = prodname.Remove(
0, 1)
50             End If
51             Dim trpath As String = Application.StartupPath &
"\Record\Record.txt"
52             File.AppendAllText(trpath, ReceiptNo.Text &
" | " & Format(Date.Now, "MM/dd/yyyy") & " | " & prodname.Trim & " | " & txtAmount.Text & " | " & Format(Val(txtCash.Text), "###,###.00") & " | " & txtChange.Text & vbCrLf)
53             With frmReceipt
54                 For i =
0 To Me.LstOrder.Items.Count - 1
55                     .LstOrder.Items.Add(LstOrder.Items(i))
56                 Next i
57                 .ReceiptNo.Text = Me.ReceiptNo.Text
58                 .lblTotal.Text = Me.txtAmount.Text
59                 .lblCash.Text = Me.txtCash.Text
60                 .lblChange.Text = Me.txtChange.Text
61                 .ShowDialog()
62             End With
63             prodname =
""
64             btnClose_Click(sender, e)
65             frmMenu.BtnClear_Click(sender, e)
66             frmMenu.dtgRecord.Rows.Clear()
67             frmMenu.Filter_Record()
68             End If
69     End Sub
70
71     Private Sub frmPayment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
72         ReceiptNo.Text =
"BURGER-" & GetUniqueKey(6)
73     End Sub
74 End Class


Gõ tìm kiếm nhanh...